#include <stdio.h>
#include <pthread.h>


pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex1=PTHREAD_MUTEX_INITIALIZER;

pthread_cond_t cond=PTHREAD_COND_INITIALIZER;
pthread_cond_t cond1=PTHREAD_COND_INITIALIZER;


void *myfunc(void *arg)
{
	while(1)
	{
		pthread_mutex_lock(&mutex);
		pthread_cond_wait(&cond,&mutex);
		printf("zi:helloworld\n");
		pthread_mutex_unlock(&mutex);
	}
}

void *myfunc1(void *arg)
{
	while(1)
	{
		pthread_mutex_lock(&mutex1);
		pthread_cond_wait(&cond1,&mutex1);
		printf("<1><2><3><4><5><6><7><8>\n");
		pthread_mutex_unlock(&mutex1);
	}
}

int main(int argc, const char *argv[])
{
	int inputnum=0;
	pthread_t tid=0;
	pthread_t tid1=0;
	pthread_create(&tid,NULL,myfunc,NULL);
	pthread_create(&tid1,NULL,myfunc1,NULL);

	while(1)
	{
		scanf("%d",&inputnum);
		switch(inputnum)
		{
		case 7:
//			pthread_mutex_lock(&mutex);
			pthread_cond_signal(&cond);
//			pthread_mutex_unlock(&mutex);
			break;
		case 8:
//			pthread_mutex_lock(&mutex1);
			pthread_cond_signal(&cond1);
//			pthread_mutex_unlock(&mutex1);
			break;
		case 9:
//			pthread_mutex_lock(&mutex);
//			pthread_mutex_lock(&mutex1);
			pthread_cond_broadcast(&cond);			
			pthread_cond_broadcast(&cond1);
//			pthread_mutex_unlock(&mutex);
//			pthread_mutex_unlock(&mutex1);

			break;

		default:
			break;
		}

	}

	return 0;
}
